#ifdef KITSCHY_DEBUG_MEMORY 
#include "debug_memorymanager.h"
#endif

#ifdef WIN32
#include "windows.h"
#endif

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"

#include <GL/gl.h>
#include <GL/glut.h>

#include "BList.h"
#include "BVector.h"
#include "geometrics.h"
#include "quaternion.h"
#include "symbol.h"
#include "sort.h"
#include "ontology.h"
#include "featureterm.h"
#include "FTKBase.h"

#include "AWLocalViewport.h"

#include "AWEntity.h"
#include "AWMessage.h"
#include "AWScenario.h"
#include "AWBody.h"
#include "AWMsgBody.h"
#include "AWSensor.h"
#include "AWBrain.h"
#include "AWAgent.h"
#include "AWWorld.h"

AW_MsgBody::AW_MsgBody(Ontology *O,FTKBase *Memory) : AW_Body(O,Memory) 
{
	operators();

	class_name->set("AW_MsgBody");
} /* AW_MsgBody */ 


AW_MsgBody::AW_MsgBody(FILE *fp,Ontology *O,FTKBase *Memory) : AW_Body(O,Memory)
{
	operators();

	class_name->set("AW_MsgBody");
	load(fp);
} /* AW_MsgBody::AW_MsgBody */ 


void AW_MsgBody::operators(void)
{
	FeatureTerm *op;

	m_ontology->new_sort("send-operator","any",2,"receiver","symbol","content","symbol");
	op=FeatureTerm::fromStringNOOS("(define (send-operator))",m_memory,m_ontology);
	m_ops.Add(op);
} /* AW_MsgBody::operators */ 


bool AW_MsgBody::load(FILE *fp)
{
	if (!AW_Body::load(fp)) return false;

	return true;
} /* AW_MsgBody::load */ 


bool AW_MsgBody::save(FILE *fp)
{
	if (!AW_Body::save(fp)) return false;

	return true;
} /* AW_MsgBody::save */ 


bool AW_MsgBody::ApplyOperator(FeatureTerm *op,float time,AW_Agent *a,AW_World *w)
{
	if (strcmp(op->getSort()->get(),"send-operator")==0) {
		Symbol *s1=0,*s2=0;
		FeatureTerm *f;

		f=op->featureValueQuick("receiver");
		if (f!=0) s1=f->getSymbol();
		f=op->featureValueQuick("content");
		if (f!=0) s2=f->getSymbol();
		if (s1==0 || s2==0) return false;
		w->sendmessage(new AW_Message(a->get_AgentName(),s1,s2));
		return true;
	} /* if */ 

	return AW_Body::ApplyOperator(op,time,a,w);
} /* AW_MsgBody::ApplyOperator */ 


bool AW_MsgBody::is_a(char *c)
{
	if (strcmp(c,"AW_MsgBody")==0) return true;

	return AW_Body::is_a(c);
} /* AW_MsgBody::is_a */ 


bool AW_MsgBody::is_a(Symbol *c)
{
	if (c->cmp("AW_MsgBody")) return true;

	return AW_Body::is_a(c);
} /* AW_MsgBody::is_a */ 
